package com.djsearch.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.djsearch.R;
import com.djsearch.ui.GroupShopDetailsActivity;
import com.djsearch.ui.JiuDianActivity;
import com.djsearch.ui.MovieActivity;
import com.djsearch.ui.RechargeActivity;
import com.djsearch.ui.SearchJiPiaoActivity;
import com.djsearch.ui.SearchJiuDianActivity;
import com.djsearch.ui.SetActivity;
import com.djsearch.ui.WanNengSearchActivity;
import com.djsearch.ui.WebViewActivity;
import com.djsearch.ui.WeiboActivity;

public class MainGridViewOtherAdapter extends BaseAdapter{
	

	
	private Context mContext;
	private Integer[] mImageIds={
			
		    R.drawable.jipiao_selector,
		    R.drawable.chongzhi_selector,
		    R.drawable.jiudian_selector,
		    R.drawable.wannengsou_selector,
		    R.drawable.weibo_selector,
		    R.drawable.set_selector
		    
		    
	};
	public MainGridViewOtherAdapter(Context context){
		mContext = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mImageIds.length;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View view = LayoutInflater.from(mContext).inflate(R.layout.main_gridview_item, null);
		ImageView imageview = (ImageView)view.findViewById(R.id.ivAppIcon);
		imageview.setImageResource(mImageIds[position]);
		imageview.setScaleType(ImageView.ScaleType.FIT_CENTER);
		imageview.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent;
				if (position == 0) {
					startToActivity(SearchJiPiaoActivity.class);
				} else if (position == 1) {
			        
			      //去看看
					Intent intentUrl=new Intent();
					intentUrl.setClass(mContext, WebViewActivity.class);
			        Bundle bundle = new Bundle();
			        bundle.putString("url", "http://wtm.m.taobao.com/?&ttid=b0cb01&sprefer=b0cb01");
			        bundle.putString("whichBuyType", "taoGou");
			        intentUrl.putExtras(bundle);
//			        intent.putExtra("url", groupBuyGoods.getShopUrl());
			        mContext.startActivity(intentUrl);
			        ((Activity) mContext).overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
			        
			        
			        
			        
				} else if (position == 2) {
					startToActivity(SearchJiuDianActivity.class);
				} else if (position == 3) {
					startToActivity(WanNengSearchActivity.class);
				} else if (position == 4) {
					startToActivity(WeiboActivity.class);
				} else if (position == 5) {
					startToActivity(SetActivity.class);
				}
				
			}
		});
		return view;
	}

	private void startToActivity(Class<?> toActivity){
		Intent intent;
		intent=new Intent(mContext, toActivity);
		mContext.startActivity(intent);
	    ((Activity) mContext).overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
//	    ((Activity) mContext).finish();
	}
	


}
